/**
 * Project: Utilities <br>
 * Package: org.leumasjaffe.io
 */
package org.leumasjaffe.io;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
 * Class org.leumasjaffe.io..StringStream in file StringStream.java <br>
 * 
 * @author leumasjaffe
 * @version Aug 23, 2013
 * Created on: Aug 23, 2013
 * 
 */
@NonNullByDefault
public class StringStream extends PrintStream {
	
	private final ByteArrayOutputStream baos;
	
	/**
	 * @param out
	 */
	public StringStream() {
		this(new ByteArrayOutputStream());
	}

	/**
	 * @param out
	 * @param autoFlush
	 */
	public StringStream(boolean autoFlush) {
		this(new ByteArrayOutputStream(), autoFlush);
	}

	/**
	 * @param out
	 * @param autoFlush
	 * @param encoding
	 * @throws UnsupportedEncodingException
	 */
	public StringStream(boolean autoFlush, String encoding)
			throws UnsupportedEncodingException {
		this(new ByteArrayOutputStream(), autoFlush, encoding);
	}

	/**
	 * @param out
	 */
	private StringStream(ByteArrayOutputStream out) {
		super(out);
		this.baos = out;
	}

	/**
	 * @param out
	 * @param autoFlush
	 */
	private StringStream(ByteArrayOutputStream out, boolean autoFlush) {
		super(out, autoFlush);
		this.baos = out;
	}

	/**
	 * @param out
	 * @param autoFlush
	 * @param encoding
	 * @throws UnsupportedEncodingException
	 */
	private StringStream(ByteArrayOutputStream out, boolean autoFlush, String encoding)
			throws UnsupportedEncodingException {
		super(out, autoFlush, encoding);
		this.baos = out;
	}
	
	@Override
	@SuppressWarnings("null")
	public String toString() {
		return this.baos.toString();
	}
	
	/**
	 * @return
	 * @see java.io.ByteArrayOutputStream#toByteArray()
	 */
	@SuppressWarnings("null")
	public byte[] toByteArray() {
		return this.baos.toByteArray();
	}

	/**
	 * @param charsetName
	 * @return
	 * @throws UnsupportedEncodingException
	 * @see java.io.ByteArrayOutputStream#toString(java.lang.String)
	 */
	@SuppressWarnings("null")
	public String toString(String charsetName)
			throws UnsupportedEncodingException {
		return this.baos.toString(charsetName);
	}


}
